package com.yunduo.controller;

import com.yunduo.common.JwtUtils;
import com.yunduo.common.RetunData.CommonReturn;
import com.yunduo.common.RetunData.statuscode.impl.ResultCode;
import com.yunduo.common.YunDuoConst.OrderState;
import com.yunduo.common.YunDuoUtils;
import com.yunduo.entity.Order;
import com.yunduo.entity.Pay;
import com.yunduo.entity.front.OrderIdAddress;
import com.yunduo.service.OrderService;
import com.yunduo.service.PayService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ChengXin
 * @since 2023-08-25
 */
@RestController
@RequestMapping("/pay")
public class PayController {

    @Resource
    private PayService payService;
    @Resource
    private OrderService orderService;
    /**
     * 到店支付
     * @param id
     * @return
     */
    @PostMapping("/localPay")
    public CommonReturn localPay(@RequestBody OrderIdAddress data){
        boolean isPay = payService.localPay(data.getOrderId(), data.getIntable());
        if(!isPay){
            return CommonReturn.ERROR(ResultCode.ERROR);
        }
        return CommonReturn.SUCCESS(ResultCode.SUCCESS);
    }
}
